# -*- coding: utf-8 -*-

import tushare as ts
import pymysql
from sqlalchemy import create_engine
from urllib.parse import quote_plus
from datetime import datetime
import pandas as pd


class StockDataFetcher:
    def __init__(self):
        """
        初始化股票数据获取类
        :param db_user: 数据库用户名
        :param db_password: 数据库密码
        :param db_host: 数据库主机地址
        :param db_port: 数据库端口
        :param db_name: 数据库名称
        :param tushare_token: tushare API token
        """
        # 配置参数
        self.db_user = 'root'
        self.db_password = 'NewPass123!@#'
        self.db_host = '10.54.1.6'
        self.db_port = 13306
        self.db_name = 'zjjk'
        self.tushare_token = 'b1125846b73e4e0445d2d8cd1ea3d7ba1443e881c78eb09acb78f6ec'
        self.pro = None
        self.engine = None        

    def init_db_connection(self):
        """
        初始化数据库连接
        """
        quoted_password = quote_plus(self.db_password)
        self.engine = create_engine(
            f'mysql+pymysql://{self.db_user}:{quoted_password}@{self.db_host}:{self.db_port}/{self.db_name}')
        return self.engine

    def init_tushare(self):
        """
        初始化 tushare API
        """
        self.pro = ts.pro_api(self.tushare_token)
        return self.pro

# ... existing code ...

if __name__ == '__main__':
    # 配置参数
    db_user = 'root'
    db_password = 'NewPass123!@#'
    db_host = '10.54.1.6'
    db_port = 13306
    db_name = 'zjjk'
    tushare_token = 'b1125846b73e4e0445d2d8cd1ea3d7ba1443e881c78eb09acb78f6ec'

    # 初始化数据获取器
    fetcher = StockDataFetcher(db_user, db_password, db_host, db_port, db_name, tushare_token)
    #engine = fetcher.init_db_connection()
    #pro = fetcher.init_tushare()
